#region Using Directives

using System;
using Eneta.Portal.Forum.Common.Data;
using Eneta.Portal.Forum.Core.Domain.Collections;
using Eneta.Portal.Forum.Core.Domain.Entities;
using Eneta.Portal.Forum.Core.Service.Application;

#endregion

namespace Eneta.Portal.Forum.Core.Data
{
    public class ForumUserDao : DataProviderBase
    {
        public int Save(ForumUser user)
        {
            return 0;
            //int userId;

            //SharePointListItem listItem = UserMapper.CreateDto(user);

            //if (user.Id == 0)
            //{
            //    userId = Provider.AddListItem(ForumConstants.Lists_Users, listItem);
            //}
            //else
            //{
            //    userId = Provider.UpdateListItem(ForumConstants.Lists_Users, listItem);
            //}

            //return userId;
        }

        /// <summary>
        /// Gets the count.
        /// </summary>
        /// <value>The count.</value>
        public int Count
        {
            get
            {
                return 0;
                //SharePointListDescriptor descriptor = Provider.GetAllListItems(ForumConstants.Lists_Users);
                //return descriptor.SharePointListItems.Length;
            }
        }

        /// <summary>
        /// Gets all.
        /// </summary>
        /// <returns></returns>
        public ForumUserCollection GetAll()
        {
            var users = new ForumUserCollection();
            return users;

            //SharePointListDescriptor descriptor = Provider.GetAllListItems(ForumConstants.Lists_Users);
            //foreach (SharePointListItem listItem in descriptor.SharePointListItems)
            //{
            //    users.Add(UserMapper.CreateDomainObject(listItem));
            //}

            //return users;
        }

        /// <summary>
        /// Gets the by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public ForumUser GetById(int id)
        {
            return null;
            //SharePointListItem listItem = Provider.GetListItemByField(ForumConstants.Lists_Users, "ID", id.ToString());

            //if (null == listItem)
            //{
            //    CreateUser(id);
            //    listItem = Provider.GetListItemByField(ForumConstants.Lists_Users, "UserID", id.ToString());
            //}

            //return UserMapper.CreateDomainObject(listItem);
        }

        /// <summary>
        /// Gets the by share point id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public ForumUser GetBySharePointId(int id)
        {
            return null;
            //SharePointListItem listItem = Provider.GetListItemByField(ForumConstants.Lists_Users, "UserID", id.ToString());

            //if (null == listItem)
            //{
            //    CreateUserFromSharePointId(id);
            //    listItem = Provider.GetListItemByField(ForumConstants.Lists_Users, "UserID", id.ToString());
            //}

            //return UserMapper.CreateDomainObject(listItem);
        }

        /// <summary>
        /// Creates the user.
        /// </summary>
        /// <param name="id">The id.</param>
        private void CreateUser(int id)
        {
            ForumUser user = new ForumUser();
            user.Name = ForumApplication.Instance.SpUser.Name;
            user.Id = id;
            user.UserId = ForumApplication.Instance.SpUser.ID;
            user.LastVisit = DateTime.Now;
            user.NumPosts = id == 1 ? 1 : 0;
            user.IsAdmin = id == 1 ? true : false;
            Save(user);
        }

        /// <summary>
        /// Creates the user from share point id.
        /// </summary>
        /// <param name="id">The id.</param>
        private void CreateUserFromSharePointId(int id)
        {
            ForumUser user = new ForumUser();
            user.Name = ForumApplication.Instance.SpUser.Name;
            user.Id = 0;
            user.UserId = id;
            user.LastVisit = DateTime.Now;
            user.NumPosts = id == 1 ? 1 : 0;
            user.IsAdmin = ForumApplication.Instance.SpUser.IsSiteAdmin ? true : false;
            Save(user);
        }

        /// <summary>
        /// Gets the last user in the system.
        /// </summary>
        /// <returns></returns>
        public ForumUser GetLast()
        {
            return null;
            //SharePointListDescriptor descriptor = Provider.GetAllListItems(ForumConstants.Lists_Users);
            //SharePointListItem item = descriptor.SharePointListItems[descriptor.SharePointListItems.Length - 1];
            //return UserMapper.CreateDomainObject(item);
        }
    }
}